<template>
  <Select v-model="innerValue" placeholder="请选择权限">
    <SelectOption v-for="item in views" :value="item.value">
      {{ item.title }}
    </SelectOption>
  </Select>
</template>
<script>
import {createModelProps, createProps} from '@/utils/index.js';
import {Select} from 'ant-design-vue';

export default {
  name: 'ViewActionSelector',
  model: createModelProps(),
  components: {
    Select,
    SelectOption: Select.Option
  },
  props: {
    value: createProps(String),
    formType: createProps(String),
    service: createProps(Function),
  },
  data() {
    return {
      views: [],
    };
  },
  methods: {
    loadViews() {
      this.service && this.service.get('/view/loadViewActions', {params: {formType: this.formType}}).then(views => {
        this.views = views;
      });
    },
  },
  watch: {
    formType: {
      handler() {
        this.$nextTick(() => this.loadViews());
      },
      immediate: true
    }
  },
  computed: {
    innerValue: {
      get() {
        return this.value;
      },
      set(value) {
        this.$emit('change', value);
      },
    }
  }
};
</script>